﻿using System;
using System.Diagnostics;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Linq;

namespace ttg_internal.Utilities.PipelineManager.Diagram.Controls
{
    public class RectConverter : IMultiValueConverter
    {
        /// <summary>
        /// Converts source values to a value for the binding target. The data binding engine calls this method when it propagates the values from source bindings to the binding target.
        /// </summary>
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            Debug.Assert(values.Length == 4);

            if (values.Any(val => val == DependencyProperty.UnsetValue))
            {
                return default(Rect);
            }

            return new Rect((double)values[0], (double)values[1], (double)values[2], (double)values[3]);
        }

        /// <summary>
        /// Converts a binding target value to the source binding values.
        /// </summary>
        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
